<?php
namespace app\admin\model;
use app\common\model\CommonModel;
use app\common\model\Supplier;

class SupplierModel extends CommonModel
{
	/**
	* 添加供应商信息
	*/
	public static function serSupplier($info)
	{
		$data['supplier_name'] = $info['supplier_name'];
		$data['name'] = $info['name'];
		$data['phone'] = $info['phone'];
		$data['address'] = $info['address'];
		$data['years'] = $info['years'];
		if(!(new Supplier())->setSupplier($data))
		{
			return back(config('state.STATUS_CODE_TWO'),config('state.STATUS_MSG_TWO'));
		}
		return back(config('state.STATUS_CODE_ONE'),config('state.STATUS_MSG_ONE'));
	}
	/**
	* 编辑供应商信息
	*/
	public static function updateSupplier($info)
	{
		$data['supplier_name'] = $info['supplier_name'];
		$data['name'] = $info['name'];
		$data['phone'] = $info['phone'];
		$data['address'] = $info['address'];
		$data['years'] = $info['years'];
		if((new Supplier())->updateSupplier(['supplier_id'=>$info['id']],$data) === false)
		{
			return back(config('state.STATUS_CODE_TWO'),config('state.STATUS_MSG_TWO'));
		}
		return back(config('state.STATUS_CODE_ONE'),config('state.STATUS_MSG_ONE'));
	}
	/**
	* 删除
	*/
	public static function delSuppliers($id)
	{
		if((new Supplier())->delSuppliers(['supplier_id'=>$id]) === false)
		{
			return back(config('state.STATUS_CODE_TWO'),config('state.STATUS_MSG_TWO'));
		}
		return back(config('state.STATUS_CODE_ONE'),config('state.STATUS_MSG_ONE'));
	}
}
